from google.appengine.ext import db

class UserProfile(db.Model):

    googleuser = db.UserProperty(required=True)
    nickname = db.StringProperty(required=True)
    datejoined = db.DateTimeProperty(auto_now_add=True)
    lastpost = db.DateTimeProperty()
    commentcounter = db.IntegerProperty(default=0)
    enabled = db.BooleanProperty(False)
    subscriber = db.BooleanProperty(default=False)

    def getKey(self):
        return self.key()

    def isValid(self):
        self.errormessage = []
        if (len(self.nickname) <5):
            self.errormessage.append('Nickname must be at least 5 characters.')
            return False
        if (len(self.nickname) >10):
            self.errormessage.append('Nickname must be no longer than 10 characters.')
            return False
        if (self.nickname[1] == ' '):
            self.errormessage.append('Nickname cannot start with a space or blank character.')
            return False
        return True




